<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
    <script type="text/javascript" include="mapv" src="../../dist/include-openlayers.js"></script>
    <title>北京村庄分布图</title>
    <style>
        .ol-popup {
            position: absolute;
            background-color: white;
            -webkit-filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
            filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
            padding: 15px;
            border-radius: 10px;
            border: 1px solid #cccccc;
            bottom: 12px;
            left: -50px;
            min-width: 280px;
            font-size: 8pt;
        }

        .ol-popup:after, .ol-popup:before {
            top: 100%;
            border: solid transparent;
            content: " ";
            height: 0;
            width: 0;
            position: absolute;
            pointer-events: none;
        }

        .ol-popup:after {
            border-top-color: white;
            border-width: 10px;
            left: 48px;
            margin-left: -10px;
        }

        .ol-popup:before {
            border-top-color: #cccccc;
            border-width: 11px;
            left: 48px;
            margin-left: -11px;
        }

        .ol-popup-closer {
            text-decoration: none;
            position: absolute;
            top: 2px;
            right: 8px;
        }

        .ol-popup-closer:after {
            content: "✖";
        }
    </style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%">
<div id="map" style="width: 100%;height:100%"></div>
<div id="popup" class="ol-popup">
    <a href="#" id="popup-closer" class="ol-popup-closer"></a>
    <div id="popup-content">示例数据来源为百度MapV的加偏数据，iClient9未做纠偏处理</div>
</div>
<script type="text/javascript">
    var container = document.getElementById('popup');
    var closer = document.getElementById('popup-closer');
    var overlay = new ol.Overlay(({
        element: container,
        autoPan: true,
        autoPanAnimation: {
            duration: 250
        }
    }));
    closer.onclick = function () {
        overlay.setPosition(undefined);
        closer.blur();
        return false;
    };
    var map = new ol.Map({
        target: 'map',
        controls: ol.control.defaults({attributionOptions: {collapsed: false}})
            .extend([new ol.supermap.control.Logo()]),
        overlays: [overlay],
        view: new ol.View({
            center: ol.proj.transform([116.443571, 39.887549], 'EPSG:4326', 'EPSG:3857'),
            zoom: 12,
            projection: 'EPSG:3857'
        })
    });

    var host = window.isLocal ? document.location.protocol + "//" + document.location.host : "http://support.supermap.com.cn:8090";
    var url = host + "/iserver/services/map-china400/rest/maps/ChinaDark";
    map.addLayer(new ol.layer.Tile({
        source: new ol.source.TileSuperMapRest({
            url: url,
            attributions: new ol.Attribution({
                html: "Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a>"
            })
        })
    }));
    overlay.setPosition(map.getView().getCenter());

    $.get('../data/beijing-village.json', function (data) {
        var dataSet = new mapv.DataSet(data);
        dataSet._data.map(function (data, i) {
            data.geometry.coordinates.map(function (coords, j) {
                coords.map(function (coord, k) {
                    dataSet._data[i].geometry.coordinates[j][k] = ol.proj.transform(coord, 'EPSG:4326', 'EPSG:3857');
                });
            })
        });
        var mapvOptions = {
            fillStyle: 'rgba(255, 80, 53, 0.8)',
            strokeStyle: 'rgba(250, 255, 53, 0.8)',
            size: 3,
            lineWidth: 1,
            draw: 'simple'
        };
        var options = {
            map: map, dataSet: dataSet, mapvOptions: mapvOptions
        };
        map.addLayer(new ol.layer.Image({
            source: new ol.source.Mapv(options)
        }));
    });


</script>
</body>
</html>
